package com.xyzk.diagnose.view.dialog;
import com.xyzk.diagnose.R;

import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


public  class LoginDialog{
	private final static String TAG = "InputVinDialog";
	private Dialog alertDialog;
	private ViewGroup alertViewGroup;
	private Activity activity = null;
	//private int width = 0;
	private Button m_onok = null;
	private Button m_onclose = null;
	public LoginDialog(Activity activity) {
		// TODO Auto-generated constructor stub
		this.activity = activity;
		WindowManager manager = activity.getWindowManager();
		Display display = manager.getDefaultDisplay();
		//width = display.getWidth() - 30;
		LayoutInflater inflater = activity.getLayoutInflater();
		alertViewGroup = (ViewGroup) inflater.inflate(R.layout.dialog_login, null);
		//alertDialog = new Dialog.Builder(activity).create();
		alertDialog = new Dialog(activity);
		alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		alertDialog.show();
		//if(Common.Debug) Log.i(TAG,"创建窗口!");
		//处理确定按钮
		m_onok = (Button)alertViewGroup.findViewById(R.id.btn_dialog_login_sure);
		m_onok.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

			}
		});
		//close
		m_onclose = (Button)alertViewGroup.findViewById(R.id.btn_dialog_login_cancel);
		m_onclose.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				alertDialog.cancel();
			}
		});
		//屏蔽返回
		alertDialog.setCancelable(false);
	}
	public void setOnKeyListener(DialogInterface.OnKeyListener keyListener)
	{
		alertDialog.setOnKeyListener(keyListener);
	}
	public LoginDialog setPositiveButton(String buttonText,OnClickListener l){
		Button positiveButton = (Button)alertViewGroup.findViewById(R.id.btn_dialog_login_sure);
		positiveButton.setOnClickListener(l);
		//positiveButton.setText(buttonText);
		//alertViewGroup.findViewById(R.id.input_vin_but_ok).setVisibility(View.VISIBLE);
		return this;
	}

	public LoginDialog setOnOKButton(OnClickListener l){
		//return setPositiveButton(activity.getResources().getString(resId),l);
		return setPositiveButton("",l);
	}
	public void cancel(){
		alertDialog.cancel();
	}

	public void dismiss(){
		alertDialog.dismiss();
	}
	public void show(){
		//alertDialog.getWindow().setLayout(width, LayoutParams.WRAP_CONTENT);
		alertDialog.getWindow().setContentView(alertViewGroup);
	}
	//set title
	public LoginDialog setTitle(String title){
		TextView titleView = (TextView)alertViewGroup.findViewById(R.id.dialog_login_title);
		titleView.setText(title);
		return this;
	}

	public LoginDialog setTitle(int resId){
		return setTitle(activity.getResources().getString(resId));
	}
	public String GetNameString()
	{
		EditText edit = (EditText)alertViewGroup.findViewById(R.id.et_dialog_login_username);
		return edit.getText().toString();
	}
	public void setNameString(String data)
	{
		EditText edit = (EditText)alertViewGroup.findViewById(R.id.et_dialog_login_username);
		edit.setText(data);
	}
	public String GetPasswordString()
	{
		EditText edit = (EditText)alertViewGroup.findViewById(R.id.et_dialog_login_password);
		return edit.getText().toString();
	}
	public void setPasswordString(String data)
	{
		EditText edit = (EditText)alertViewGroup.findViewById(R.id.et_dialog_login_password);
		edit.setText(data);
	}

}
